<?php
require_once 'source/init.php';
$op = get_get("op");
global $_GCONFIG;
global $mail;
if ($op == "register" && isAjaxRequest()) {
    if ($_GCONFIG["user"]["allowRegister"] == false) {
        err("管理员未开放注册");
    }
    $pass = (get_post("password"));
    $name = (get_post("name"));
    $email = (get_post("email"));
    if ($pass == "" || $name == "" || $email == "") {
        fail("你必须完整填写所有信息");
        finish();
    }
    if (strlen($pass) < 6) {
        fail("密码必须大于6位");
    }
    $regex = "/([a-z0-9]*[-_.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[.][a-z]{2,3}([.][a-z]{2})?/i";
    if (! preg_match($regex, $email)) {
        fail("您的邮箱格式不合法");
    }
    if (! register($name, $pass, $email, true)) {
        fail("注册失败，可能是你的邮箱已经被注册过了。如有异议请联系管理员。");
    }
    success("注册成功");
   
}
if ($op == "result") {
    if (! isAjaxRequest()) {
        if ($_GCONFIG["user"]["forceVerify"]) {
            $mail = true;
        }
        loadTemp("system/register_result_temp.php");
        die();
    }
}
if (isLogined()) {
    header("location:index.php");
} else {
    loadTemp("system/register_temp.php");
    die();
}

?>